﻿namespace cludg.Repository.Transactions.NHibernate
{
	public class TransactionFactory : ITransactionFactory
	{
		protected readonly Repository.NHibernate.Sessions.INHibernateSessionController SessionController;

		public TransactionFactory(Repository.NHibernate.Sessions.INHibernateSessionController sessionController)
		{
			SessionController = sessionController;
		}

		public ITransaction BeginTransaction()
		{
			if (SessionController.Current.Transaction.IsActive)
				return new NullTransaction();

			var realTran = SessionController.Current.BeginTransaction();
			return new Transaction(realTran);
		}
	}
}
